<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    

<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="utf-8">
    <meta name="keywords" content="ADO.NET+SqlHelper, Zhou•Yong">
    <meta name="description" content="ADO.NET+自己封装的SqlHelper 理论到处都是的，我就不写理论了，两张图表达一切： 下面直接写demo练习和自己封装一个sqlHelper分享大家看看
连接 static public void TestConnection()">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>ADO.NET+SqlHelper | Zhou•Yong</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/css/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>

</head>

<body>

<header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="container">
            <div class="nav-wrapper">
                <div class="brand-logo">
                    <a href="/" class="waves-effect waves-light">
                        
                        <img src="/medias/logo.png" class="logo-img hide-on-small-only">
                        
                        <span class="logo-span">Zhou•Yong</span>
                    </a>
                </div>
                <a href="#" data-activates="mobile-nav" class="button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right">
    
    <li class="hide-on-med-and-down">
        <a href="/" class="waves-effect waves-light">
            
            <i class="fa fa-home"></i>
            
            <span>主页</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/about" class="waves-effect waves-light">
            
            <i class="fa fa-user-circle-o"></i>
            
            <span>个人介绍</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/categories" class="waves-effect waves-light">
            
            <i class="fa fa-bookmark"></i>
            
            <span>分类</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/tags" class="waves-effect waves-light">
            
            <i class="fa fa-tags"></i>
            
            <span>标签</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/friends" class="waves-effect waves-light">
            
            <i class="fa fa-address-book"></i>
            
            <span>推荐</span>
        </a>
    </li>
    
    <li>
        <a id="toggleSearch" class="waves-effect waves-light">
            <i id="searchIcon" class="mdi-action-search"></i>
        </a>
    </li>

</ul>

<div class="side-nav" id="mobile-nav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">Zhou•Yong</div>
        <div class="logo-desc">
            
            你迈出的步伐不非得很大，只要你是在正确的方向前进就行
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li>
            <a href="/" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-home"></i>
                
                主页
            </a>
        </li>
        
        <li>
            <a href="/about" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-user-circle-o"></i>
                
                个人介绍
            </a>
        </li>
        
        <li>
            <a href="/categories" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-bookmark"></i>
                
                分类
            </a>
        </li>
        
        <li>
            <a href="/tags" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-tags"></i>
                
                标签
            </a>
        </li>
        
        <li>
            <a href="/friends" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-address-book"></i>
                
                推荐
            </a>
        </li>
        
        
    </ul>

    <div class="social-link"><a href="#!" class="tooltipped" data-tooltip="邮件联系我: zy20081@126.com" data-position="top" data-delay="50">
    <i class="fa fa-envelope-open"></i>
</a>
<a href="#!" class="tooltipped" data-tooltip="QQ联系我: 314153271" data-position="top" data-delay="50">
    <i class="fa fa-qq"></i>
</a>

<a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
    <i class="fa fa-rss"></i>
</a>
</div>
</div>

            </div>
        </div>

        
    </nav>
</header>





<div class="bg-cover post-cover" style="background-image: url('/medias/featureimages/12.jpg')">
    <div class="container">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        ADO.NET+SqlHelper
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1,
    #articleContent h2,
    #articleContent h3,
    #articleContent h4,
    #articleContent h5,
    #articleContent h6 {
        padding-top: 76px;
        margin-top: -76px;
    }

    #articleContent h1 {
        line-height: 3.5rem;
    }

    #articleContent h2 {
        line-height: 3.2rem;
    }

    #articleContent h3 {
        line-height: 2.8rem;
    }

    #articleContent h4 {
        line-height: 2.5rem;
    }

    #articleContent h5 {
        line-height: 2.2rem;
    }

    #articleContent h6 {
        line-height: 1.9rem;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }
</style>
<div class="row">
    <div class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            
            <div class="article-tag">
                
                <a href="/tags/ADO-NET/" target="_blank">
                    <span class="chip bg-color">ADO.NET</span>
                </a>
                
            </div>
            
            <div class="post-info">
                
                <span class="post-cate">
                    <i class="fa fa-bookmark fa-fw icon-category"></i>
                    
                    <a href="/categories/ASP-NET/" class="post-category" target="_blank">
                        ASP.NET
                    </a>
                    
                </span>
                

                <span class="post-date">
                    <i class="fa fa-clock-o fa-fw"></i>2019-01-08
                </span>
            </div>
        </div>
        <hr>
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="ADO-NET-自己封装的SqlHelper"><a href="#ADO-NET-自己封装的SqlHelper" class="headerlink" title="ADO.NET+自己封装的SqlHelper"></a>ADO.NET+自己封装的SqlHelper</h2><p> 理论到处都是的，我就不写理论了，两张图表达一切：<br><img src="/2019/01/08/ado.net/1.jpg" alt="图1"><br><img src="/2019/01/08/ado.net/2.jpg" alt="图2"><br> 下面直接写demo练习和自己封装一个sqlHelper分享大家看看</p>
<h2 id="连接"><a href="#连接" class="headerlink" title="连接"></a>连接</h2><pre class=" language-bash"><code class="language-bash"> static public void TestConnection<span class="token punctuation">(</span><span class="token punctuation">)</span> //连接
        <span class="token punctuation">{</span>
        //1.连接通道的连接字符串
            string Constr <span class="token operator">=</span> @<span class="token string">"server=.;database=book;uid=sa;pwd=sa"</span><span class="token punctuation">;</span>
        //2.连接通道
           SqlConnection con<span class="token operator">=</span>new SqlConnection<span class="token punctuation">(</span>Constr<span class="token punctuation">)</span><span class="token punctuation">;</span> 
         //3.打开通道
            con.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          //4.关闭通道
            con.Close<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            Console.WriteLine<span class="token punctuation">(</span><span class="token string">"连接上数据库了"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            //注意如果是orcale的，方式不同：
            OleDbConnection conn <span class="token operator">=</span> new OleDbConnection<span class="token punctuation">(</span><span class="token string">"Provider=MSDAORA.1;Data Source=(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.234)(PORT = 1521)))(CONNECT_DATA = (SID = orcl))) ;User Id=sjk;Password=sssss"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            conn.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            string sql <span class="token operator">=</span> <span class="token string">"select * from tbl_aa "</span><span class="token punctuation">;</span>
            OleDbDataAdapter da <span class="token operator">=</span> new OleDbDataAdapter<span class="token punctuation">(</span>sql, conn<span class="token punctuation">)</span><span class="token punctuation">;</span>
            DataSet ds <span class="token operator">=</span> new DataSet<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            da.Fill<span class="token punctuation">(</span>ds, <span class="token string">"ds"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            dataGridView1.DataSource <span class="token operator">=</span> ds.Tables<span class="token punctuation">[</span>0<span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
</code></pre>
<h2 id="查询单个值"><a href="#查询单个值" class="headerlink" title="查询单个值"></a>查询单个值</h2><pre class=" language-bash"><code class="language-bash">   static public void QuerySingle<span class="token punctuation">(</span><span class="token punctuation">)</span> //查询单个值  SqlCommand .ExecuteScalar<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            string constr <span class="token operator">=</span> @<span class="token string">"server=.;database=book;uid=sa;pwd=sa;"</span><span class="token punctuation">;</span>
            SqlConnection  con<span class="token operator">=</span>new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">)</span><span class="token punctuation">;</span>
            string sqlstr <span class="token operator">=</span> <span class="token string">"select count(*) from Category"</span><span class="token punctuation">;</span>
            SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span>sqlstr, con<span class="token punctuation">)</span><span class="token punctuation">;</span>
            con.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            object obj <span class="token operator">=</span> cmd.ExecuteScalar<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            con.Close<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            Console.WriteLine<span class="token punctuation">(</span>obj.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
</code></pre>
<h2 id="增，删，改"><a href="#增，删，改" class="headerlink" title="增，删，改"></a>增，删，改</h2><pre class=" language-bash"><code class="language-bash"> static public void AddRecord<span class="token punctuation">(</span><span class="token punctuation">)</span> //增，删，改 SqlCommand ExecuteNonQuery<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            int res <span class="token operator">=</span> 0<span class="token punctuation">;</span> //准备接受新橧
        //1.连接通道的字符串
            string Constr <span class="token operator">=</span> @<span class="token string">"server=.;database=book;uid=sa;pwd=sa;"</span><span class="token punctuation">;</span>
        //2.连接通道
            SqlConnection con <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
       //3.手动指定连接字符串
            con.ConnectionString <span class="token operator">=</span> Constr<span class="token punctuation">;</span>
       //4.准备insert字符串语句
            string sqlstr <span class="token operator">=</span> <span class="token string">"insert into Category(C_name,C_remark,C_isdel,C_addtime)values('编程书籍','asp.net','0',GetDate())"</span><span class="token punctuation">;</span>
        //5.新建命令对象（工人），并告诉哪里走，做什么
            SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span>sqlstr, con<span class="token punctuation">)</span><span class="token punctuation">;</span>
            //cmd.CommandText <span class="token operator">=</span> sqlstr<span class="token punctuation">;</span>
            //cmd.Connection <span class="token operator">=</span> con<span class="token punctuation">;</span>
         //打开连接通道
            con.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
         //6.调用方法去执行sql语句
            res <span class="token operator">=</span> cmd.ExecuteNonQuery<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//此方法负责增删改，返回受影响的行数（int）
            //关闭连接通道
            con.Close<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>res <span class="token operator">></span> 0<span class="token punctuation">)</span>
            <span class="token punctuation">{</span>
                Console.WriteLine<span class="token punctuation">(</span><span class="token string">"新增成功"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">else</span> <span class="token punctuation">{</span> Console.WriteLine<span class="token punctuation">(</span><span class="token string">"新增失败"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>

        <span class="token punctuation">}</span>
</code></pre>
<h2 id="查询多行数据-SqlDataReader"><a href="#查询多行数据-SqlDataReader" class="headerlink" title="查询多行数据 SqlDataReader"></a>查询多行数据 SqlDataReader</h2><pre class=" language-bash"><code class="language-bash"> static public void QueryList<span class="token punctuation">(</span><span class="token punctuation">)</span> //查询多行数据 SqlDataReader
        <span class="token punctuation">{</span>
            string constr <span class="token operator">=</span> @<span class="token string">"server=.;database=book;uid=sa;pwd=sa;"</span><span class="token punctuation">;</span>
            SqlConnection con <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">)</span><span class="token punctuation">;</span>
            string sqlstr <span class="token operator">=</span> <span class="token string">"select * from Category"</span><span class="token punctuation">;</span>
            SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span>sqlstr, con<span class="token punctuation">)</span><span class="token punctuation">;</span>
            con.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            SqlDataReader dr <span class="token operator">=</span> cmd.ExecuteReader<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>dr.HasRows<span class="token punctuation">)</span>//是返回返回结果
            <span class="token punctuation">{</span>
                <span class="token keyword">while</span> <span class="token punctuation">(</span>dr.Read<span class="token punctuation">(</span><span class="token punctuation">))</span>//前进下一行记录
                <span class="token punctuation">{</span>
                    //Console.WriteLine<span class="token punctuation">(</span>dr<span class="token punctuation">[</span>4<span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
                    //for <span class="token punctuation">(</span>int i <span class="token operator">=</span> 0<span class="token punctuation">;</span> i <span class="token operator">&lt;</span> 5<span class="token punctuation">;</span> i++<span class="token punctuation">)</span>
                    //<span class="token punctuation">{</span>
                    //    Console.WriteLine<span class="token punctuation">(</span>dr<span class="token punctuation">[</span>i<span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
                    //<span class="token punctuation">}</span>
                    Console.WriteLine<span class="token punctuation">(</span>dr<span class="token punctuation">[</span><span class="token string">"C_id"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_name"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_remark"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_isdel"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> +<span class="token string">"+"</span>+ dr<span class="token punctuation">[</span><span class="token string">"C_addtime"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
                    //Console.WriteLine<span class="token punctuation">(</span>dr.GetOrdinal<span class="token punctuation">(</span><span class="token string">"C_id"</span><span class="token punctuation">)</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>

                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">else</span> <span class="token punctuation">{</span> Console.WriteLine<span class="token punctuation">(</span><span class="token string">"无数据"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span>
            dr.Close<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            con.Close<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
</code></pre>
<h2 id="使用适配器读取数据-填充数据集-SqlDataAdapter"><a href="#使用适配器读取数据-填充数据集-SqlDataAdapter" class="headerlink" title="使用适配器读取数据,填充数据集 SqlDataAdapter"></a>使用适配器读取数据,填充数据集 SqlDataAdapter</h2><pre class=" language-bash"><code class="language-bash">  static public void QueryListByAdapter<span class="token punctuation">(</span><span class="token punctuation">)</span> //使用适配器读取数据,填充数据集 SqlDataAdapter
        <span class="token punctuation">{</span>
            string str <span class="token operator">=</span> @<span class="token string">"server=.;database=book;uid=sa;pwd=sa;"</span><span class="token punctuation">;</span>
            SqlConnection con <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
            string sqlstr <span class="token operator">=</span> <span class="token string">"select * from Category"</span><span class="token punctuation">;</span>
            //创建适配器，告诉它要做什么事情，走那条路
            SqlDataAdapter da <span class="token operator">=</span> new SqlDataAdapter<span class="token punctuation">(</span>sqlstr, con<span class="token punctuation">)</span><span class="token punctuation">;</span>
            //创建数据集对象（程序端的临时数据库）
            DataSet ds <span class="token operator">=</span> new DataSet<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            //调用fill方法，填充数据集（先去数据库查询数据集，并把结果集返回赋值给数据集）
            da.Fill<span class="token punctuation">(</span>ds,<span class="token string">"table1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            //获取数据集中的每一张表
            DataTable dt <span class="token operator">=</span> ds.Tables<span class="token punctuation">[</span><span class="token string">"table1"</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            //循环数据表中的每一行
            <span class="token keyword">for</span> <span class="token punctuation">(</span>int i <span class="token operator">=</span> 0<span class="token punctuation">;</span> i <span class="token operator">&lt;</span> dt.Rows.Count<span class="token punctuation">;</span>i++ <span class="token punctuation">)</span>
            <span class="token punctuation">{</span>
                DataRow dr <span class="token operator">=</span> dt.Rows<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
                //每一行里的每一列
                Console.WriteLine<span class="token punctuation">(</span>dr<span class="token punctuation">[</span><span class="token string">"C_id"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_name"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_remark"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_isdel"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_addtime"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
         <span class="token punctuation">}</span>
</code></pre>
<h2 id="使用适配器读取数据-填充表-SqlDataAdapter"><a href="#使用适配器读取数据-填充表-SqlDataAdapter" class="headerlink" title="使用适配器读取数据,填充表 SqlDataAdapter"></a>使用适配器读取数据,填充表 SqlDataAdapter</h2><pre class=" language-bash"><code class="language-bash">  static public void QueryListByAdapter2<span class="token punctuation">(</span><span class="token punctuation">)</span> //使用适配器读取数据,填充表 SqlDataAdapter
        <span class="token punctuation">{</span>
            string str <span class="token operator">=</span> @<span class="token string">"server=.;database=book;uid=sa;pwd=sa;"</span><span class="token punctuation">;</span>
            SqlConnection con <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
            string sqlstr <span class="token operator">=</span> <span class="token string">"select * from Category"</span><span class="token punctuation">;</span>
            //创建适配器，告诉它要做什么事情，走那条路
            SqlDataAdapter da <span class="token operator">=</span> new SqlDataAdapter<span class="token punctuation">(</span>sqlstr, con<span class="token punctuation">)</span><span class="token punctuation">;</span>
            //创建数据表（程序端的临时数据库）
            DataTable dt <span class="token operator">=</span> new DataTable<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            //调用fill方法，填充数据集（先去数据库查询数据集，并把结果集返回赋值给数据集）
            da.Fill<span class="token punctuation">(</span>dt<span class="token punctuation">)</span><span class="token punctuation">;</span>
            //循环数据表中的每一行
            foreach <span class="token punctuation">(</span>DataRow dr <span class="token keyword">in</span> dt.Rows<span class="token punctuation">)</span> 
            <span class="token punctuation">{</span>
                Console.WriteLine<span class="token punctuation">(</span>dr<span class="token punctuation">[</span><span class="token string">"C_id"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_name"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_remark"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_isdel"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_addtime"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            //for <span class="token punctuation">(</span>int i <span class="token operator">=</span> 0<span class="token punctuation">;</span> i <span class="token operator">&lt;</span> dt.Rows.Count<span class="token punctuation">;</span> i++<span class="token punctuation">)</span>
            //<span class="token punctuation">{</span>
            //    DataRow dr <span class="token operator">=</span> dt.Rows<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
            //    //每一行里的每一列
            //    Console.WriteLine<span class="token punctuation">(</span>dr<span class="token punctuation">[</span><span class="token string">"C_id"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_name"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_remark"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_isdel"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_addtime"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
            //<span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
</code></pre>
<h2 id="调用存储过程-单个参数"><a href="#调用存储过程-单个参数" class="headerlink" title="调用存储过程 单个参数"></a>调用存储过程 单个参数</h2><pre class=" language-bash"><code class="language-bash"> static public void QueryListByProc<span class="token punctuation">(</span><span class="token punctuation">)</span> //调用存储过程 单个参数
        <span class="token punctuation">{</span>
            string str <span class="token operator">=</span> @<span class="token string">"server=.;database=book;uid=sa;pwd=sa;"</span><span class="token punctuation">;</span>
            SqlConnection con <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
            SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span><span class="token string">"usp_getBook"</span>, con<span class="token punctuation">)</span><span class="token punctuation">;</span>
            cmd.CommandType <span class="token operator">=</span> CommandType.StoredProcedure<span class="token punctuation">;</span> //指定命令类型为存储过程
            SqlParameter sp<span class="token operator">=</span>new SqlParameter<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//指定存储过程中的参数
            sp.ParameterName <span class="token operator">=</span> <span class="token string">"@CateId"</span><span class="token punctuation">;</span>
            sp.SqlDbType <span class="token operator">=</span> SqlDbType.Int<span class="token punctuation">;</span>
            sp.Value <span class="token operator">=</span> 3<span class="token punctuation">;</span>
            cmd.Parameters.Add<span class="token punctuation">(</span>sp<span class="token punctuation">)</span><span class="token punctuation">;</span>
            SqlDataAdapter da <span class="token operator">=</span> new SqlDataAdapter<span class="token punctuation">(</span>cmd<span class="token punctuation">)</span><span class="token punctuation">;</span>//将参数对象加入到命令对象的参数集合中
            DataTable dt <span class="token operator">=</span> new DataTable<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            da.Fill<span class="token punctuation">(</span>dt<span class="token punctuation">)</span><span class="token punctuation">;</span>
            foreach <span class="token punctuation">(</span>DataRow dr <span class="token keyword">in</span> dt.Rows<span class="token punctuation">)</span>
            <span class="token punctuation">{</span>
                Console.WriteLine<span class="token punctuation">(</span>dr<span class="token punctuation">[</span><span class="token string">"C_id"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_name"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_remark"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_isdel"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span> + <span class="token string">"+"</span> + dr<span class="token punctuation">[</span><span class="token string">"C_addtime"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>

        <span class="token punctuation">}</span>
</code></pre>
<h2 id="调用存储过程，多参数"><a href="#调用存储过程，多参数" class="headerlink" title="调用存储过程，多参数"></a>调用存储过程，多参数</h2><pre class=" language-bash"><code class="language-bash">        static public void QueryListByProc2<span class="token punctuation">(</span><span class="token punctuation">)</span>//调用存储过程，多参数 
        <span class="token punctuation">{</span>
            string str <span class="token operator">=</span> @<span class="token string">"server=.;database=Bank;uid=sa;pwd=sa;"</span><span class="token punctuation">;</span>
            SqlConnection con <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
            SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span><span class="token string">"getBank"</span>, con<span class="token punctuation">)</span><span class="token punctuation">;</span>
            cmd.CommandType <span class="token operator">=</span> CommandType.StoredProcedure<span class="token punctuation">;</span>//指定作为存储过程执行
            SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> sp <span class="token operator">=</span> <span class="token punctuation">{</span> new SqlParameter<span class="token punctuation">(</span><span class="token string">"@pageSize"</span>, SqlDbType.Int, 4<span class="token punctuation">)</span>,
                                  new SqlParameter<span class="token punctuation">(</span><span class="token string">"@pageindex"</span>,SqlDbType.Int,4<span class="token punctuation">)</span>,
                                  new SqlParameter<span class="token punctuation">(</span><span class="token string">"@rowCount"</span>,SqlDbType.Int,4<span class="token punctuation">)</span>,
                                  new SqlParameter<span class="token punctuation">(</span><span class="token string">"@pageCount"</span>,SqlDbType.Int,4<span class="token punctuation">)</span>

                                <span class="token punctuation">}</span><span class="token punctuation">;</span>
            sp<span class="token punctuation">[</span>0<span class="token punctuation">]</span>.Value <span class="token operator">=</span> 2<span class="token punctuation">;</span>//设置搜索第一页
            sp<span class="token punctuation">[</span>1<span class="token punctuation">]</span>.Value <span class="token operator">=</span> 5<span class="token punctuation">;</span>//设置显示的页数
            sp<span class="token punctuation">[</span>2<span class="token punctuation">]</span>.Direction <span class="token operator">=</span> ParameterDirection.Output<span class="token punctuation">;</span>//输出参数
            sp<span class="token punctuation">[</span>3<span class="token punctuation">]</span>.Direction <span class="token operator">=</span> ParameterDirection.Output<span class="token punctuation">;</span>
            //sp<span class="token punctuation">[</span>2<span class="token punctuation">]</span>.Value <span class="token operator">=</span> 5<span class="token punctuation">;</span>
            //sp<span class="token punctuation">[</span>3<span class="token punctuation">]</span>.Value <span class="token operator">=</span> 5<span class="token punctuation">;</span>
            cmd.Parameters.AddRange<span class="token punctuation">(</span>sp<span class="token punctuation">)</span><span class="token punctuation">;</span>//为cmd对象添加参数数组
            SqlDataAdapter da <span class="token operator">=</span> new SqlDataAdapter<span class="token punctuation">(</span>cmd<span class="token punctuation">)</span><span class="token punctuation">;</span>//创建适配器
            DataTable dt <span class="token operator">=</span> new DataTable<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>//创建数据表（程序端）
            da.Fill<span class="token punctuation">(</span>dt<span class="token punctuation">)</span><span class="token punctuation">;</span>
            foreach <span class="token punctuation">(</span>DataRow dr <span class="token keyword">in</span> dt.Rows<span class="token punctuation">)</span> 
            <span class="token punctuation">{</span>
                Console.WriteLine<span class="token punctuation">(</span>dr<span class="token punctuation">[</span><span class="token string">"R"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span>+<span class="token string">"+"</span>+dr<span class="token punctuation">[</span><span class="token string">"bankID"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span>+<span class="token string">"+"</span>+dr<span class="token punctuation">[</span><span class="token string">"customerName"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">)</span>+<span class="token string">"+"</span>+dr<span class="token punctuation">[</span><span class="token string">"currentMoney"</span><span class="token punctuation">]</span>.ToString<span class="token punctuation">(</span><span class="token punctuation">))</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            int rowCount <span class="token operator">=</span> Convert.ToInt32<span class="token punctuation">(</span>cmd.Parameters<span class="token punctuation">[</span>2<span class="token punctuation">]</span>.Value<span class="token punctuation">)</span><span class="token punctuation">;</span>
            int pageCount <span class="token operator">=</span> Convert.ToInt32<span class="token punctuation">(</span>cmd.Parameters<span class="token punctuation">[</span>3<span class="token punctuation">]</span>.Value<span class="token punctuation">)</span><span class="token punctuation">;</span>
            Console.WriteLine<span class="token punctuation">(</span><span class="token string">"{0},{1}"</span>,rowCount,pageCount<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token punctuation">}</span>
</code></pre>
<h2 id="SqlHelper"><a href="#SqlHelper" class="headerlink" title="SqlHelper"></a>SqlHelper</h2><pre class=" language-bash"><code class="language-bash">using System<span class="token punctuation">;</span>
using System.Collections.Generic<span class="token punctuation">;</span>
using System.Linq<span class="token punctuation">;</span>
using System.Text<span class="token punctuation">;</span>
using System.Data<span class="token punctuation">;</span>
using System.Configuration<span class="token punctuation">;</span>
using System.Data.SqlClient<span class="token punctuation">;</span>

namespace Power_2.DAL
<span class="token punctuation">{</span>
    class SqlHelper
    <span class="token punctuation">{</span> //每次打开一个连接保持快速连接
        private static <span class="token function">readonly</span> string constr <span class="token operator">=</span> ConfigurationManager.ConnectionStrings<span class="token punctuation">[</span><span class="token string">"conStr"</span><span class="token punctuation">]</span>.ConnectionString<span class="token punctuation">;</span>
        //封装方法的原则：把不变大的放到方法里，把变化的放参数中到
        private static SqlConnection conn<span class="token punctuation">;</span> //连接

        public static SqlConnection Conn
        <span class="token punctuation">{</span>
            get
            <span class="token punctuation">{</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>conn <span class="token operator">==</span> null <span class="token operator">||</span> conn.State <span class="token operator">==</span> ConnectionState.Broken<span class="token punctuation">)</span>
                <span class="token punctuation">{</span>
                    conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                <span class="token keyword">return</span> conn<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>

        <span class="token punctuation">}</span>
        /// <span class="token operator">&lt;</span>summary<span class="token operator">></span>
        /// 析构函数，自动消除，防止没有删除完，程序自动调用
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"sql"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        ~SqlHelper<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            Dispose<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        public void Dispose<span class="token punctuation">(</span><span class="token punctuation">)</span> //写个方法可以调用回收
        <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>conn <span class="token operator">!=</span> null<span class="token punctuation">)</span>
            <span class="token punctuation">{</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>conn.State <span class="token operator">!=</span> ConnectionState.Closed<span class="token punctuation">)</span>
                    conn.Close<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                conn.Dispose<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        /// <span class="token operator">&lt;</span>summary<span class="token operator">></span>
        /// 执行的语句 执行增删改
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"sql"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        public static int ExecuteNonQuery<span class="token punctuation">(</span>string sql<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            using <span class="token punctuation">(</span>SqlConnection conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">))</span>
            <span class="token punctuation">{</span>
                conn.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                using <span class="token punctuation">(</span>SqlCommand cmd <span class="token operator">=</span> conn.CreateCommand<span class="token punctuation">(</span><span class="token punctuation">))</span>
                <span class="token punctuation">{</span>
                    cmd.CommandText <span class="token operator">=</span> sql<span class="token punctuation">;</span>
                    <span class="token keyword">return</span> cmd.ExecuteNonQuery<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        /// <span class="token operator">&lt;</span>summary<span class="token operator">></span>
        /// 参数执行的语句 执行增删改
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"sqlstr"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"paras"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        public static int ExecuteNonQuery<span class="token punctuation">(</span>string sqlstr, params SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> paras<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            using <span class="token punctuation">(</span>SqlConnection conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">))</span>
            <span class="token punctuation">{</span>
                conn.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span>sqlstr, conn<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>paras <span class="token operator">!=</span> null <span class="token operator">&amp;&amp;</span> paras.Length <span class="token operator">></span> 0<span class="token punctuation">)</span>
                <span class="token punctuation">{</span>
                    cmd.Parameters.AddRange<span class="token punctuation">(</span>paras<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                int res <span class="token operator">=</span> 0<span class="token punctuation">;</span>
                try
                <span class="token punctuation">{</span>
                    res <span class="token operator">=</span> cmd.ExecuteNonQuery<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                catch <span class="token punctuation">(</span>Exception ex<span class="token punctuation">)</span>
                <span class="token punctuation">{</span>

                    throw ex<span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                finally
                <span class="token punctuation">{</span>
                    <span class="token keyword">if</span> <span class="token punctuation">(</span>cmd <span class="token operator">!=</span> null<span class="token punctuation">)</span>
                    <span class="token punctuation">{</span>
                        <span class="token keyword">if</span> <span class="token punctuation">(</span>cmd.Parameters.Count <span class="token operator">></span> 0<span class="token punctuation">)</span>
                        <span class="token punctuation">{</span>
                            cmd.Parameters.Clear<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                        cmd.Dispose<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        cmd <span class="token operator">=</span> null<span class="token punctuation">;</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
                Conn.Close<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">return</span> res<span class="token punctuation">;</span>

            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        public static object ExecuteScalar<span class="token punctuation">(</span>string sql<span class="token punctuation">)</span> //查询单个值
        <span class="token punctuation">{</span>
            using <span class="token punctuation">(</span>SqlConnection conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">))</span>
            <span class="token punctuation">{</span>
                conn.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                using <span class="token punctuation">(</span>SqlCommand cmd <span class="token operator">=</span> conn.CreateCommand<span class="token punctuation">(</span><span class="token punctuation">))</span>
                <span class="token punctuation">{</span>
                    cmd.CommandText <span class="token operator">=</span> sql<span class="token punctuation">;</span>
                    <span class="token keyword">return</span> cmd.ExecuteScalar<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        public static object ExecuteScalar<span class="token punctuation">(</span>string sql, params SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> paras<span class="token punctuation">)</span> //查询单个值
        <span class="token punctuation">{</span>
            using <span class="token punctuation">(</span>SqlConnection conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">))</span>
            <span class="token punctuation">{</span>
                conn.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                using <span class="token punctuation">(</span>SqlCommand cmd <span class="token operator">=</span> conn.CreateCommand<span class="token punctuation">(</span><span class="token punctuation">))</span>
                <span class="token punctuation">{</span>
                    cmd.Parameters.AddRange<span class="token punctuation">(</span>paras<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    cmd.CommandText <span class="token operator">=</span> sql<span class="token punctuation">;</span>
                    <span class="token keyword">return</span> cmd.ExecuteScalar<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        /// <span class="token operator">&lt;</span>summary<span class="token operator">></span>
        /// 查询结果集比较少的sql
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"sql"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"paras"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        public static DataTable ExecuteDataTable<span class="token punctuation">(</span>string sql, params SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> paras<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            using <span class="token punctuation">(</span>SqlConnection conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">))</span>
            <span class="token punctuation">{</span>
                conn.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span>sql,conn<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>paras <span class="token operator">!=</span> null <span class="token operator">&amp;&amp;</span> paras.Length <span class="token operator">></span> 0<span class="token punctuation">)</span>
                <span class="token punctuation">{</span>
                    cmd.Parameters.AddRange<span class="token punctuation">(</span>paras<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                SqlDataAdapter adapter <span class="token operator">=</span> new SqlDataAdapter<span class="token punctuation">(</span>cmd<span class="token punctuation">)</span><span class="token punctuation">;</span>
                DataTable dt <span class="token operator">=</span> new DataTable<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                try
                <span class="token punctuation">{</span>

                    adapter.Fill<span class="token punctuation">(</span>dt<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                catch <span class="token punctuation">(</span>Exception ex<span class="token punctuation">)</span>
                <span class="token punctuation">{</span>

                    throw ex<span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                finally
                <span class="token punctuation">{</span>
                    <span class="token keyword">if</span> <span class="token punctuation">(</span>adapter <span class="token operator">!=</span> null<span class="token punctuation">)</span>
                    <span class="token punctuation">{</span>
                        adapter.Dispose<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        adapter <span class="token operator">=</span> null<span class="token punctuation">;</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
                <span class="token keyword">return</span> dt<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        public static SqlDataReader ExecuteDataReader<span class="token punctuation">(</span>string cmdText, params SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parameters<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            SqlConnection conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">)</span><span class="token punctuation">;</span>
            conn.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            using <span class="token punctuation">(</span>SqlCommand cmd <span class="token operator">=</span> conn.CreateCommand<span class="token punctuation">(</span><span class="token punctuation">))</span>
            <span class="token punctuation">{</span>
                cmd.CommandText <span class="token operator">=</span> cmdText<span class="token punctuation">;</span>
                cmd.Parameters.AddRange<span class="token punctuation">(</span>parameters<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">return</span> cmd.ExecuteReader<span class="token punctuation">(</span>CommandBehavior.CloseConnection<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        /// <span class="token operator">&lt;</span>summary<span class="token operator">></span>
        /// 执行简单分页存储过程
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"pageIndex"</span><span class="token operator">></span>每页行数<span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"pageSize"</span><span class="token operator">></span>当前页面数<span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"rowCount"</span><span class="token operator">></span>总行数（传出参数）<span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"pageCount"</span><span class="token operator">></span>总页数（传出参数）<span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        public static DataTable ExecProSimplePageList<span class="token punctuation">(</span>int pageIndex, int pageSize, out int rowCount, out int pageCount<span class="token punctuation">)</span> 
        <span class="token punctuation">{</span>
            rowCount <span class="token operator">=</span> 1<span class="token punctuation">;</span>
            pageCount <span class="token operator">=</span> 1<span class="token punctuation">;</span>
            SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parameters <span class="token operator">=</span><span class="token punctuation">{</span>
                                      new SqlParameter<span class="token punctuation">(</span><span class="token string">"@pageindex"</span>,SqlDbType.Int,4<span class="token punctuation">)</span>,
                                       new SqlParameter<span class="token punctuation">(</span><span class="token string">"@pageSize "</span>,SqlDbType.Int,4<span class="token punctuation">)</span>,
                                       new SqlParameter<span class="token punctuation">(</span><span class="token string">"@rowCount "</span>,SqlDbType.Int,4<span class="token punctuation">)</span>,
                                       new SqlParameter<span class="token punctuation">(</span><span class="token string">"@pageCount"</span>,SqlDbType.Int,4<span class="token punctuation">)</span>
                                      <span class="token punctuation">}</span><span class="token punctuation">;</span>
            parameters<span class="token punctuation">[</span>0<span class="token punctuation">]</span>.Value <span class="token operator">=</span> pageIndex<span class="token punctuation">;</span>
            parameters<span class="token punctuation">[</span>1<span class="token punctuation">]</span>.Value <span class="token operator">=</span> pageSize<span class="token punctuation">;</span>
            parameters<span class="token punctuation">[</span>2<span class="token punctuation">]</span>.Value <span class="token operator">=</span> rowCount<span class="token punctuation">;</span>
            parameters<span class="token punctuation">[</span>2<span class="token punctuation">]</span>.Direction <span class="token operator">=</span> ParameterDirection.Output<span class="token punctuation">;</span>
            parameters<span class="token punctuation">[</span>3<span class="token punctuation">]</span>.Value <span class="token operator">=</span> pageCount<span class="token punctuation">;</span>
            parameters<span class="token punctuation">[</span>3<span class="token punctuation">]</span>.Direction <span class="token operator">=</span> ParameterDirection.Output<span class="token punctuation">;</span>
            SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
             using <span class="token punctuation">(</span>SqlConnection conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">))</span><span class="token punctuation">{</span>
                 cmd.Connection <span class="token operator">=</span> conn<span class="token punctuation">;</span>
                 cmd.CommandText <span class="token operator">=</span> <span class="token string">"usp_Book_paging"</span><span class="token punctuation">;</span>
                 cmd.CommandType <span class="token operator">=</span> CommandType.StoredProcedure<span class="token punctuation">;</span>
                 cmd.Parameters.AddRange<span class="token punctuation">(</span>parameters<span class="token punctuation">)</span><span class="token punctuation">;</span>
                 SqlDataAdapter da <span class="token operator">=</span> new SqlDataAdapter<span class="token punctuation">(</span>cmd<span class="token punctuation">)</span><span class="token punctuation">;</span>
                 DataTable dt <span class="token operator">=</span> new DataTable<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                 da.Fill<span class="token punctuation">(</span>dt<span class="token punctuation">)</span><span class="token punctuation">;</span>
                 rowCount <span class="token operator">=</span> Convert.ToInt32<span class="token punctuation">(</span>parameters<span class="token punctuation">[</span>2<span class="token punctuation">]</span>.Value<span class="token punctuation">)</span><span class="token punctuation">;</span>
                 pageCount <span class="token operator">=</span> Convert.ToInt32<span class="token punctuation">(</span>parameters<span class="token punctuation">[</span>3<span class="token punctuation">]</span>.Value<span class="token punctuation">)</span><span class="token punctuation">;</span>
                 <span class="token keyword">return</span> dt<span class="token punctuation">;</span>
             <span class="token punctuation">}</span>      
        <span class="token punctuation">}</span>
        public static object FromDbValue<span class="token punctuation">(</span>object value<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>value <span class="token operator">==</span> DBNull.Value<span class="token punctuation">)</span>
            <span class="token punctuation">{</span>
                <span class="token keyword">return</span> null<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">else</span>
            <span class="token punctuation">{</span>
                <span class="token keyword">return</span> value<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>

        public static object ToDbValue<span class="token punctuation">(</span>object value<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>value <span class="token operator">==</span> null<span class="token punctuation">)</span>
            <span class="token punctuation">{</span>
                <span class="token keyword">return</span> DBNull.Value<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">else</span>
            <span class="token punctuation">{</span>
                <span class="token keyword">return</span> value<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        ////////////////////执行存储过程的增删查改//////////////////////////
        private static SqlConnection CNN
        <span class="token punctuation">{</span>
            get
            <span class="token punctuation">{</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>conn <span class="token operator">==</span> null<span class="token punctuation">)</span>
                <span class="token punctuation">{</span>
                    conn <span class="token operator">=</span> new SqlConnection<span class="token punctuation">(</span>constr<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>

                <span class="token keyword">if</span> <span class="token punctuation">(</span>conn.State <span class="token operator">!=</span> ConnectionState.Open<span class="token punctuation">)</span>
                <span class="token punctuation">{</span>
                    conn.Open<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>

                <span class="token keyword">return</span> conn<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token comment" spellcheck="true">#region 连接等都写在一个方法里</span>
        private static SqlCommand CreateCommand<span class="token punctuation">(</span>string cmdText, CommandType cmdType, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            SqlCommand cmd <span class="token operator">=</span> new SqlCommand<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            cmd.Connection <span class="token operator">=</span> CNN<span class="token punctuation">;</span>
            cmd.CommandText <span class="token operator">=</span> cmdText<span class="token punctuation">;</span>
            cmd.CommandType <span class="token operator">=</span> cmdType<span class="token punctuation">;</span>

            <span class="token keyword">if</span> <span class="token punctuation">(</span>parms <span class="token operator">!=</span> null<span class="token punctuation">)</span>
            <span class="token punctuation">{</span>
                cmd.Parameters.AddRange<span class="token punctuation">(</span>parms<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">return</span> cmd<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        /// 
        <span class="token comment" spellcheck="true">#endregion &lt;summary></span>
        ///执行增删改功能储存过程
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"cmdText"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        <span class="token comment" spellcheck="true">#region ExecuteCommand</span>
        public static int ExecuteCommand<span class="token punctuation">(</span>string cmdText<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> ExecuteCommand<span class="token punctuation">(</span>cmdText, null<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        public static int ExecuteCommand<span class="token punctuation">(</span>string cmdText, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> ExecuteCommand<span class="token punctuation">(</span>cmdText, CommandType.StoredProcedure, parms<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        public static int ExecuteCommand<span class="token punctuation">(</span>string cmdText, CommandType cmdType, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            SqlCommand cmd <span class="token operator">=</span> CreateCommand<span class="token punctuation">(</span>cmdText, cmdType, parms<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">return</span> cmd.ExecuteNonQuery<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment" spellcheck="true">#endregion</span>
        /// <span class="token operator">&lt;</span>summary<span class="token operator">></span>
        /// 返回一张表
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"cmdText"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        <span class="token comment" spellcheck="true">#region GetTable</span>
        public static DataTable GetTable<span class="token punctuation">(</span>string cmdText<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> GetTable<span class="token punctuation">(</span>cmdText, null<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        public static DataTable GetTable<span class="token punctuation">(</span>string cmdText, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> GetTable<span class="token punctuation">(</span>cmdText, CommandType.StoredProcedure, parms<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        public static DataTable GetTable<span class="token punctuation">(</span>string cmdText, CommandType cmdType, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            DataTable table <span class="token operator">=</span> new DataTable<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            SqlDataAdapter adapter <span class="token operator">=</span> new SqlDataAdapter<span class="token punctuation">(</span>CreateCommand<span class="token punctuation">(</span>cmdText, cmdType, parms<span class="token punctuation">))</span><span class="token punctuation">;</span>
            adapter.Fill<span class="token punctuation">(</span>table<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">return</span> table<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment" spellcheck="true">#endregion</span>
        /// <span class="token operator">&lt;</span>summary<span class="token operator">></span>
        /// SqlDataReader可以读一行行数据的对象、查询多行数据 SqlDataReader
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"cmdText"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        <span class="token comment" spellcheck="true">#region GetReader</span>
        public static SqlDataReader GetReader<span class="token punctuation">(</span>string cmdText<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> GetReader<span class="token punctuation">(</span>cmdText, null<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        public static SqlDataReader GetReader<span class="token punctuation">(</span>string cmdText, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> GetReader<span class="token punctuation">(</span>cmdText, CommandType.StoredProcedure, parms<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        public static SqlDataReader GetReader<span class="token punctuation">(</span>string cmdText, CommandType cmdType, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            SqlCommand cmd <span class="token operator">=</span> CreateCommand<span class="token punctuation">(</span>cmdText, cmdType, parms<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">return</span> cmd.ExecuteReader<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment" spellcheck="true">#endregion</span>
        /// <span class="token operator">&lt;</span>summary<span class="token operator">></span>
        /// 返回单个值
        /// <span class="token operator">&lt;</span>/summary<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>param name<span class="token operator">=</span><span class="token string">"cmdText"</span><span class="token operator">></span><span class="token operator">&lt;</span>/param<span class="token operator">></span>
        /// <span class="token operator">&lt;</span>returns<span class="token operator">></span><span class="token operator">&lt;</span>/returns<span class="token operator">></span>
        <span class="token comment" spellcheck="true">#region GetScalar</span>
        public static object GetScalar<span class="token punctuation">(</span>string cmdText<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> GetScalar<span class="token punctuation">(</span>cmdText, null<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        public static object GetScalar<span class="token punctuation">(</span>string cmdText, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token keyword">return</span> GetScalar<span class="token punctuation">(</span>cmdText, CommandType.StoredProcedure, parms<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        public static object GetScalar<span class="token punctuation">(</span>string cmdText, CommandType cmdType, SqlParameter<span class="token punctuation">[</span><span class="token punctuation">]</span> parms<span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            SqlCommand cmd <span class="token operator">=</span> CreateCommand<span class="token punctuation">(</span>cmdText, cmdType, parms<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">return</span> cmd.ExecuteScalar<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment" spellcheck="true">#endregion</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>

            </div>
            <hr>

            
            <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.88rem;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff;
        background-color: #22AB38;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff;
        background-color: #019FE8;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a class="reward-link btn-floating btn-large waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close"><i class="fa fa-close"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs">
                        <li class="tab wechat-tab waves-effect waves-light"><a class="active" href="#wechat">微信</a></li>
                        <li class="tab alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                    </ul>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('#reward .reward-link').on('click', function () {
            $('#rewardModal').openModal();
        });

        $('#rewardModal .close').on('click', function () {
            $('#rewardModal').closeModal();
        });
    });
</script>
            

            <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    <div class="social-share" data-disabled="qzone" data-wechat-qrcode-helper="<p>微信里点“发现”->“扫一扫”二维码便可查看分享。</p>"></div>
    
</div>

<script src="/libs/share/js/social-share.min.js"></script>

            <div class="reprint">
                <p>
                    <span class="reprint-tip">转载请注明: </span>
                    <a href="https://zy20081.github.io" class="b-link-green">Zhou•Yong</a>
                    <i class="fa fa-angle-right fa-lg fa-fw text-color"></i>
                    <a href="/2019/01/08/ado.net/" class="b-link-green">ADO.NET+SqlHelper</a>
                </p>
            </div>
        </div>
    </div>

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">上一篇</div>
            <div class="card">
                <a href="/2019/01/09/asp.net-zhi-shi-dian-zong-jie/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/7.jpg" class="responsive-img" alt=".net总结">
                        
                        <span class="card-title">.net总结</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary">Asp.NET 知识点总结(一)1.简述 private、 protected、 public、 internal 修饰符的访问权限。
答 . private : 私有类，私有成员, 在类的内部才可以访问。
protected : 保护成员</div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="fa fa-clock-o fa-fw icon-date"></i>2019-01-09
                        </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/ASP-NET/" class="post-category" target="_blank">
                                    ASP.NET
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/ASP-NET/" target="_blank">
                        <span class="chip bg-color">ASP.NET</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">下一篇</div>
            <div class="card">
                <a href="/2019/01/08/xml/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/17.jpg" class="responsive-img" alt="XML解析demo">
                        
                        <span class="card-title">XML解析demo</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary">创建xml  static void Main(string[] args)
  {  //1.创建一个XDocument对象
      XDocument writeXml = new XDocument();
     //2.增加一</div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="fa fa-clock-o fa-fw icon-date"></i>2019-01-08
                            </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/ASP-NET/" class="post-category" target="_blank">
                                    ASP.NET
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/C-Demo/" target="_blank">
                        <span class="chip bg-color">C# Demo</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>
</div>


    </div>
    <div class="col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title">目录</div>
            <div id="toc-content">

            </div>
        </div>
    </div>
</div>

<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });
    });
</script>
    

</main>


<footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            本站由ZhouYong 技术分享，心得分享.
        </div>
        <div class="col s12 m4 l4 social-link"><a href="#!" class="tooltipped" data-tooltip="邮件联系我: zy20081@126.com" data-position="top" data-delay="50">
    <i class="fa fa-envelope-open"></i>
</a>
<a href="#!" class="tooltipped" data-tooltip="QQ联系我: 314153271" data-position="top" data-delay="50">
    <i class="fa fa-qq"></i>
</a>

<a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
    <i class="fa fa-rss"></i>
</a>
</div>
    </div>
</footer>

<div class="progress-bar"></div>


<!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title">搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字" class="search-input" autofocus>
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
</script>
<!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fa fa-angle-up"></i>
    </a>
</div>


<script src="/libs/materialize/js/materialize.min.js"></script>
<script src="/libs/masonry/masonry.pkgd.min.js"></script>
<script src="/libs/aos/aos.js"></script>
<script src="/libs/scrollprogress/scrollProgress.min.js"></script>
<script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>

<script src="/libs/others/clicklove.js"></script>

<script src="/js/matery.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->


</body>
</html>